package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IAppOrderService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.AppOrderCreateValidate;
import com.mdd.admin.validate.AppOrderUpdateValidate;
import com.mdd.admin.validate.AppOrderSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.AppOrderListedVo;
import com.mdd.admin.vo.AppOrderDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/appOrder")
@Api(tags = "快递订单提交管理")
public class AppOrderController {

    @Resource
    IAppOrderService iAppOrderService;

    @GetMapping("/list")
    @ApiOperation(value="快递订单提交列表")
    public AjaxResult<PageResult<AppOrderListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated AppOrderSearchValidate searchValidate) {
        PageResult<AppOrderListedVo> list = iAppOrderService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="快递订单提交详情")
    public AjaxResult<AppOrderDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        AppOrderDetailVo detail = iAppOrderService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "快递订单提交新增")
    @PostMapping("/add")
    @ApiOperation(value="快递订单提交新增")
    public AjaxResult<Object> add(@Validated @RequestBody AppOrderCreateValidate createValidate) {
        iAppOrderService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "快递订单提交编辑")
    @PostMapping("/edit")
    @ApiOperation(value="快递订单提交编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody AppOrderUpdateValidate updateValidate) {
        iAppOrderService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "快递订单提交删除")
    @PostMapping("/del")
    @ApiOperation(value="快递订单提交删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iAppOrderService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
